package com.falcon.web.security;

import com.falcon.authority.api.IUserApi;
import com.falcon.authority.domain.po.ApiPO;
import com.swan.security.domain.SecurityUserInfo;
import com.swan.security.security.IApiSelector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/** 用户接口权限列表查询
 * @author zongf
 * @date 2025-02-21
 **/
@Component
public class SecurityApiSelector implements IApiSelector {

    @Autowired
    private IUserApi userApi;

    @Override
    public List<String> queryAuthApis(SecurityUserInfo userInfo) {
        if (Objects.isNull(userInfo) || Objects.isNull(userInfo.getId())) {
            return List.of();
        }

        List<ApiPO> apiPOS = this.userApi.queryUserApis(userInfo.getId());
        return apiPOS.stream().map(ApiPO::getRequestUri).toList();
    }
}
